package br.com.Orange.view.action.cliente;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import br.com.Orange.negocio.Fachada;
import br.com.Orange.negocio.cliente.exception.ClienteInexistenteException;
import br.com.Orange.negocio.cliente.model.Cliente;
import br.com.Orange.view.form.cliente.ConsultarClienteForm;

public class ConsultarClienteAction extends Action {

	/* (non-Javadoc)
	 * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		Cliente cli = ((ConsultarClienteForm)form).getCliente();
		
		
		try{
			Cliente encontrado = Fachada.obterInstancia().procurarCliente(cli.getCPF());
			request.setAttribute("cliente", encontrado);
		}catch (ClienteInexistenteException ex) {
			return mapping.findForward("Erro");
		}
		
		return mapping.findForward("success");
		
	}
	
	

}
